package 网络编程.课后作业;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * 1)、查看指定URL的HTML源文档内容？
 * 提示：使用URL类和URLConnection类
 *
 * String url = “https://www.cnblogs.com/itboxue/p/10738810.html”;
 */
public class M2 {
    public static void main(String[] args) throws IOException {
            String url = "https://www.cnblogs.com/itboxue/p/10738810.html";
        BufferedReader reader = null;
        StringBuilder builder = new StringBuilder();

        try {
            URL u = new URL(url);
            URLConnection uc = u.openConnection();

            reader = new BufferedReader(new InputStreamReader(uc.getInputStream(),"UTF-8"));
            String msg = null;
            while ((msg = reader.readLine())!=null){
                builder.append(msg);
                builder.append("\r\n");
            }
            System.out.println(builder.toString());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            {
                if (reader!=null){
                    reader.close();
                }
            }
        }
    }
}
